package com.gitee.wsl.net.token.identity

data class IdentityConfiguration(
    var username: String? = null,
    var password: String? = null
)

class InMemoryIdentity : IdentityService {
    private val identities = mutableListOf<IdentityConfiguration>()

    fun identity(inline: IdentityConfiguration.() -> Unit): InMemoryIdentity {
        val client = IdentityConfiguration()
        inline(client)

        identities.add(client)
        return this
    }

    override fun identityOf( username: String): Identity? {
        val findConfiguration = findConfiguration(username) ?: return null
        return Identity(findConfiguration.username!!)
    }

    //override fun allowedScopes( identity: Identity, scopes: Set<String>) = scopes

    /*override fun validCredentials( identity: Identity, password: String): Boolean =
        findConfiguration(identity.username)!!.password == password*/


    private fun findConfiguration(username: String) = identities.firstOrNull { it.username == username }
}